﻿using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using HZ.MBSM.Model;
using HZ.MBSM.DBUtility;

public partial class Manage_InfoUpLoad : System.Web.UI.Page
{
    Int64 InfoId;
    Boolean count;
    protected void Page_Load(object sender, EventArgs e)
    {
        /// 在此处放置用户代码以初始化页面
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (this.IsPostBack)
            {

                InfoId = SysFun.ToInt(SysFun.IsSQL(Request.QueryString["InfoId"]));
                if (count == false)
                {
                    this.SaveImages();
                }
            }
            else
            {
                count = false;

            }
        }
    }
    private Boolean SaveImages()
    {
        string sql;
        string  download = "";
        string LoadFileName = "";
        ///'遍历File表单元素
        HttpFileCollection files = HttpContext.Current.Request.Files;

        /// '状态信息

        System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
        strMsg.Append("上传的文件分别是：<hr color=red>");
        try
        {
            for (int iFile = 0; iFile < files.Count; iFile++)
            {
                ///'检查文件扩展名字

                HttpPostedFile postedFile = files[iFile];
                string fileName, fileExtension;
                fileName = System.IO.Path.GetFileName(postedFile.FileName);
                if (fileName != "")
                {
                    LoadFileName = fileName;
                    fileExtension = System.IO.Path.GetExtension(fileName);
                    strMsg.Append("上传的文件类型：" + postedFile.ContentType.ToString() + "<br>");
                    strMsg.Append("客户端文件地址：" + postedFile.FileName + "<br>");
                    strMsg.Append("上传文件的文件名：" + fileName + "<br>");
                    strMsg.Append("上传文件的扩展名：" + fileExtension + "<br><hr>");
                    ///'可根据扩展名字的不同保存到不同的文件夹

                    ///注意：可能要修改你的文件夹的匿名写入权限。

                    postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("../UploadFile/") + fileName);

                }
            }
            Db db = new Db();
            System.Data.IDataReader dr;
            sql = "select DownLoad  from info where InfoId="+ InfoId +" and download is not null";
            dr = db.DataReader(sql);
            while (dr.Read())
            {
                download =SysFun.ToTrim(dr["DownLoad"]);
            }
            dr.Dispose();
            dr.Close();
            if ((SysFun.ToTrim(download)).Length != 0)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                /*strStatus.Text = "还没发布招标公告!,不能上传文件";
                db.Close();
                return false;*/
                sb.Append(download);
                sb.Append(",");
                sb.Append(LoadFileName);
                sql = "update Info set DownLoad='" + sb.ToString() + "' where InfoId=" + InfoId;
                db.Command(sql);
                db.Close();
                strStatus.Text = strMsg.ToString();
                count = true;
                return true;
                
            }
            else
            {
                sql = "update Info set DownLoad='" + LoadFileName + "' where InfoId=" + InfoId;
                db.Command(sql);
                db.Close();
                strStatus.Text = strMsg.ToString();
                count = true;
                return true;
            }

        }
        catch (System.Exception Ex)
        {
            strStatus.Text = Ex.Message;

            return false;
        }
    }
    #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。

        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改

    /// 此方法的内容。

    /// </summary>
    private void InitializeComponent()
    {
        this.ID = "Upload";
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

}


